<?php 
class SearchForm extends CFormModel{
	public $searchword;
	
	public function rules(){
		return array(
			array('searchword','required'),
			//array('searchword','length','max'=>50),
		);
	}
	public function check(){
		
	}
	public function splitword(){
		if($this->searchword){
			$messageenc = rawurlencode(strip_tags(preg_replace("/\[.+?\]/U", '',urldecode($this->searchword))));
			$subjectenc = rawurlencode(strip_tags(urldecode($this->searchword)));
		}
		$data = @implode('', file("http://keyword.discuz.com/related_kw.html?title=$subjectenc&content=$messageenc&ics=utf-8&ocs=utf-8"));
		
		if($data) {
			$parser = xml_parser_create();
			xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
			xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
			xml_parse_into_struct($parser, $data, $values, $index);
			xml_parser_free($parser);

			$kws = array();

			foreach($values as $valuearray) {
				if($valuearray['tag'] == 'kw' || $valuearray['tag'] == 'ekw') {
						$kws[] = trim($valuearray['value']);
				}
			}
			return $kws;
		} else {
			return false;
		}
	}
}
?>